package com.example.demo.api;

import com.example.demo.bean.Response;
import com.example.demo.bean.bis.Sign;
import com.example.demo.bean.dto.SignPlus;
import com.example.demo.service.bis.SignService;
import com.example.demo.utils.ConstantUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author zzz
 * @Title: SignController
 * @ProjectName test
 * @Description: TODO(签到controller)
 * @date 2018/7/12
 */

@CrossOrigin
@RestController
@Api(value="签到controller",tags={"签到接口"})
public class SignController {

    @Autowired SignService signService;


    @ApiOperation(value="获取个人签到排名及信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer",paramType = "form"),
            @ApiImplicitParam(name = "date", value = "日期(格式：2018-07-11)", required = true, dataType = "String",paramType = "form"),
    })
    @PostMapping(value = "/sign/day")
    public Response findByDateAndUid(Integer id, String date){
        /*try {
            System.out.println(DateUtils.getDatePoor(DateUtils.dateParse("2017-07-13 12:21:33",null),DateUtils.dateParse("2017-07-12 12:22:33",null)));
        } catch (ParseException e) {
            e.printStackTrace();
        }*/
        /*try {
         img = InetAddress.getLocalHost().toString().split("/")[1]+ img;
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }*/
        Sign sign = signService.findByDayAndUid(date,id);
       /* if (!StringUtils.isEmpty(sign) &&  !StringUtils.isEmpty(sign.getImgUrl())){
            sign.setImgUrl(img+sign.getImgUrl());
            sign.setImgMinUrl(img+sign.getImgMinUrl());
        }*/
        return new Response(ConstantUtils.SUCCEED,ConstantUtils.STRING_SUCCEED,sign);
    }


    @ApiOperation(value="按照年月日统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "date", value = "日期(格式：2018-07-07)", required = true, dataType = "String",paramType = "form"),
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "int",paramType = "form"),
    })
    @PostMapping(value = "/sign")
    public Response findByUid(String date, Integer id){
        return new Response(ConstantUtils.SUCCEED,ConstantUtils.STRING_SUCCEED,signService.findByUidAndDate(date,id));
    }
    @ApiOperation(value="按照年月统计(用于经理统计)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "date", value = "日期(格式：2018-07-07)", required = true, dataType = "String",paramType = "form"),
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "int",paramType = "form"),
            @ApiImplicitParam(name = "flag", value = "标志位传值表示查看详情", required = false, dataType = "String",paramType = "form"),
    })
    @PostMapping(value = "/signall")
    public Response findByDept(String date, Integer id,String flag){
        return new Response(ConstantUtils.SUCCEED,ConstantUtils.STRING_SUCCEED,signService.findByDeptDate(date,id,flag));
    }


    @ApiOperation(value="按照日统计(视频列表)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = false, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "date", value = "时间", required = true, dataType = "String",paramType = "query"),
    })
    @GetMapping(value = "/signall")
    public Response findByDay(String id,String date){
        List<SignPlus> list = signService.findByDay(id,date);
        return new Response(ConstantUtils.SUCCEED,ConstantUtils.STRING_SUCCEED,list.size()==ConstantUtils.SUCCEED?"":list);
    }



    @ApiOperation(value="统计部门签到信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "date", value = "日期(格式：2018 、 2018-07 、 2018-07-07   )", required = true, dataType = "String",paramType = "form"),
            @ApiImplicitParam(name = "detpId", value = "部门ID", required = true, dataType = "Integer",paramType = "form")
    })
    @PostMapping(value = "/sign/dept")
    public Response findByDeptidAndDate( Integer detpId,String date){
        return new Response(ConstantUtils.SUCCEED,ConstantUtils.STRING_SUCCEED,signService.findByDeptidAndTime(detpId,date));
    }

    @ApiOperation(value="统计部门签到详情信息(年月)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "date", value = "日期(格式：2018 、 2018-07    )", required = true, dataType = "String",paramType = "form"),
            @ApiImplicitParam(name = "detpId", value = "部门ID", required = true, dataType = "integer",paramType = "form")
    })
    @PostMapping(value = "/sign/deptdetails")
    public Response findByDeptidDetails( Integer detpId,String date){
        return new Response(ConstantUtils.SUCCEED,ConstantUtils.STRING_SUCCEED,signService.findByDeptidAndTimeDetails(detpId,date));
    }


    @ApiOperation(value="按照日统,计详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deptId", value = "部门id", required = false, dataType = "int",paramType = "form"),
            @ApiImplicitParam(name = "id", value = "用户id", required = false, dataType = "int",paramType = "form"),
            @ApiImplicitParam(name = "date", value = "时间", required = true, dataType = "String",paramType = "form"),
    })
    @PostMapping(value = "/sign/daydetails")
    public Response findByDayDetails(Integer id,Integer deptId,String date){
        return new Response(ConstantUtils.SUCCEED,ConstantUtils.STRING_SUCCEED,signService.findBySignDetils(date,id,deptId));
    }
}
